package com.jrapider.manager.controller.user;

import com.alibaba.fastjson.JSONObject;
import com.jrapider.controller.BaseCrudController;
import com.jrapider.manager.service.user.SysUserService;
import com.jrapider.manager.data.om.SysUser;
import com.jrapider.om.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/user")
@Api(tags = {"sysUser"})
public class SysUserController extends BaseCrudController<SysUserService, SysUser> {

    @ApiOperation("保存")
    @RequestMapping(
            value = {"/data/save"},
            method = {RequestMethod.POST}
    )
    @ResponseBody
    @Override
    public JSONObject save(SysUser data) {
        if (service.saveData(data)) {
            return JSONResult.newBuilder().success("保存成功").setData(data.getId()).build();
        } else {
            return JSONResult.newBuilder().fail("保存失败").build();
        }
    }

    @Override
    public void buildCondition(QueryWrapper<SysUser> qw, SysUser condition, String filter) {
        if (!StringUtils.isEmpty(filter)) {
            qw.like("login_id", filter)
                    .or().like("name", filter)
                    .or().like("mobile", filter);
        }

    }
}
